package com.gitee.ly.chain.abstractclass;

import com.gitee.ly.chain.Form;
import com.gitee.ly.chain.Link;

import java.util.List;

/**
 * AbstractTemplateLink
 *
 * @author ly
 **/
public final class AbstractTemplateLink implements Link {
    private int sort = -1;
    private String type;
    private String name;
    private String belongFlowType;

    private AbstractTemplateLink() {
    }

    AbstractTemplateLink(int sort, String type, String name) {
        if (sort < 0) {
            throw new RuntimeException("环节的顺序大小需要>=0");
        }
        this.sort = sort;
        this.type = type;
        this.name = name;
    }

    @Override
    public int getSort() {
        return sort;
    }

    @Override
    public String getType() {
        return type;
    }

    @Override
    public String getName() {
        return name;
    }

    protected void setBelongFlowType(String flowType) {
        belongFlowType = flowType;
    }

    @Override
    public List<Form> allForm() {
        return GlobalTool.getFormListByLinkType(this.type);
    }

    protected void excute(String uid, Object data) {
        for (Form form : allForm()) {
            if (form instanceof AbstractForm) {
                ((AbstractForm) form).excuteInner(uid, belongFlowType, type, data);
            }
        }
    }

}
